package com.cms.common.model.vo;

import com.cms.common.model.entity.BaseEntity;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 菜单
 */
@Data
public class Menu extends BaseEntity {
    private String name;
    private String route = null;
    private String icon = null;
    private List<Menu> children = null;
    private boolean open = false;
    private boolean active = false;
    private List<String> prefixes = null;

    public static Menu createMenu(String name, String icon, String route, List<Menu> children, String prefixe) {
        List<String> prefixes = null;
        if (prefixe != null && !prefixe.equals("")) {
            prefixes = new ArrayList<>();
            prefixes.add(prefixe);
        }
        return createMenu(name, icon, route, children, prefixes);
    }

    public static Menu createMenu(String name, String icon, String route, List<Menu> children, List<String> prefixes) {
        Menu menu = new Menu();
        menu.setName(name);
        menu.setIcon(icon);
        menu.setRoute(route);
        menu.setChildren(children);
        if (prefixes != null && prefixes.size() > 0) {
            menu.setPrefixes(prefixes);
        }
        return menu;
    }

    public static Menu createMenu(String name, String icon, List<String> prefixes, List<Menu> children) {
        return createMenu(name, icon, null, children, prefixes);
    }

    public static Menu createMenu(String name, String icon, String route, List<String> prefixes) {
        return createMenu(name, icon, route, null, prefixes);
    }

    public static Menu createMenu(String name, String icon, String route, String prefixe) {
        List<String> prefixes = null;
        if (prefixe != null && !prefixe.equals("")) {
            prefixes = new ArrayList<>();
            prefixes.add(prefixe);
        }
        return createMenu(name, icon, route, null, prefixes);
    }
}
